#!/usr/bin/python
import pymysql.cursors

def getConnection():
	connection=pymysql.connect(host='localhost',user='root',password='mysql',db='exchange_stock',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
	return connection


def insert(sql):
	conn=getConnection()
	try:
		with conn.cursor() as cursor:
			cursor.execute(sql)
	
		conn.commit()
	finally:
		conn.close()


def search(sql):
	conn=getConnection()
	try:
		with conn.cursor() as cursor:
			cursor.execute(sql)
			record = cursor.fetchone()
			if record:
				return record
			else:
				return 2
		conn.commit()
	finally:
		conn.close()

def getLines(sql):
	conn=getConnection()
	try:
		with conn.cursor() as cursor:
			cursor.execute(sql)
			record=cursor.fetchall()
			if record:
				return record
			else:
				return 2
		conn.commit()	
	finally:
		conn.close()

	
